// pages/expert/expertDetail.js

const defaultSettings = require('../../config/defaultSettings')
import {repair,save} from '../../api/eqRepair'
import {eqUrl,queryEqTypeByEqNo} from '../../api/eq'
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    defaultSettings,
    repairDetail:{},
    repairDetailForm:null,
    primaryColor:defaultSettings.primaryColor,
    emp:app.globalData.appInfo.emp,
    loading:false,
    isShowCondition:false,
    formAttributes:[
      {field:'eqName',label:'设备名称',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'eqType',label:'设备类型',component:'select',disabled:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}],dictCode:defaultSettings.dictCodes.eqFenlei},
      // {field:'eqNum',label:'设备数量',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}],type:'number'},
      {field:'pwNo',label:'所属机井',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      
      {field:'eqNo',label:'设备编号',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'operatorName',label:'报修人',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'empPhone',label:'联系电话',component:'input',readonly:true,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'createTime',label:'报修时间',component:'date',disabled:true,type:'datetime',required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'repairDesc',label:'故障原因',component:'select',disabled:true,required:false,isShowLabel:true,border:true,clean:true,dictCode:defaultSettings.dictCodes.gzyy,rules: [{required: false, message: '不能为空'}]},

      {field:'repairReason',label:'排查原因',component:'input',type:'textarea',readonly:false,required:true,isShowLabel:true,hide:false,border:true,clean:true,rules: [{required: true, message: '不能为空'}]},

      {field:'repairContent',label:'维修内容',component:'input',type:'textarea',readonly:false,required:true,isShowLabel:true,hide:false,border:true,clean:true,rules: [{required: true, message: '不能为空'}]},

      {field:'repairResult',label:'维修结果',component:'input',type:'textarea',readonly:false,required:true,isShowLabel:true,hide:false,border:true,clean:true,rules: [{required: true, message: '不能为空'}]},
    ],
    markers:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: "设备维修",
    })

    let repairDetail = wx.getStorageSync('eqRepairItem')
    this.setData({repairDetail:repairDetail})
    this.setMapMarker()
  },
  setMapMarker(){
    if(this.data.repairDetail && this.data.repairDetail.mapLongitude && this.data.repairDetail.mapLatitude){
      this.setData({markers:[{id: 1,latitude: this.data.repairDetail.mapLatitude,longitude: this.data.repairDetail.mapLongitude,name: '报修点', width: 30, height: 30}]})
    }
  },
  onChange(e){ },
  
  onSubmit(){
    this.data.repairDetailForm = this.selectComponent("#repairDetailForm")
    if(this.data.repairDetailForm.onVerify()){
      this.setData({loading:true})
      this.data.repairDetail = this.data.repairDetailForm.getFormData()
      repair(this.data.repairDetail).then(res=>{
        if(res.success){
          wx.showToast({title: '操作成功',icon: 'success'})
          this.setData({repairDetail:res.result})
        }else{
          wx.showToast({icon:"none",title: res.message})
        }
      }).finally(()=>{
        this.setData({loading:false})
      })
    }
    
  },
  onShowPup(){
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
   
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})